home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / ALARM.AML < prev    next >
Text File  |  1996-07-17  |  5KB  |  182 lines

  1. //--------------------------------------------------------------------
  2. // ALARM.AML
  3. // Set Alarm, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Alarm.dox for user help)
  6. //
  7. // This macro displays a dialog box which allows you to set up to four
  8. // editor alarms. Alarm fields are saved in the file Alarm.dat.
  9. //
  10. // Usage:
  11. //
  12. // Select this macro from the Macro List (on the Macro menu), or run it
  13. // from the macro picklist <shift f12>.
  14. //--------------------------------------------------------------------
  15.  
  16. // compile time macros and function definitions
  17. include bootpath "define.aml"
  18.  
  19. // clock timer delay
  20. constant clock_delay  = 1000
  21.  
  22. // disable <loading>, <saving> in Ext.aml while this macro is running
  23. event <loading> end
  24. event <saving> end
  25.  
  26. private function setalarm2 (setopt alarm time date macro parm)
  27.  
  28.   variable hh, mm, ss
  29.   variable YY, MM, DD, W
  30.  
  31.   timerid = "alarm" + alarm
  32.  
  33.   // turn timer on
  34.   if pos alarm setopt then
  35.  
  36.     // get the alarm times
  37.     parse "{[0-9*]#}.+{[0-9*]#}.+{[0-9*]#}" time 'x'
  38.            ref hh ref mm ref ss
  39.     parse "{[0-9*]#}.+{[0-9*]#}.+{[0-9*]#}.+{[0-6*]#}" date 'x'
  40.            ref YY ref MM ref DD ref W
  41.  
  42.     // check for wildcards
  43.     if hh == '*' then  hh = -1  end
  44.     if mm == '*' then  mm = -1  end
  45.     if ss == '*' then  ss = -1  end
  46.     if YY == '*' then  YY = -1  end
  47.     if MM == '*' then  MM = -1  end
  48.     if DD == '*' then  DD = -1  end
  49.     if W  == '*' then  W  = -1  end
  50.  
  51.     // external macro
  52.     if pos '.' macro then
  53.       setalarm timerid YY MM DD W hh mm ss ''
  54.                "runmacro" (forceext (bootpath "macro\\" + macro) 'x')
  55.     // function
  56.     else
  57.       if macro then
  58.         setalarm timerid YY MM DD W hh mm ss '' macro parm
  59.       else
  60.         setalarm timerid YY MM DD W hh mm ss '' "msgbox" parm "Alarm" 'b'
  61.       end
  62.     end
  63.  
  64.   // turn timer off
  65.   else
  66.     destroytimer timerid
  67.   end
  68. end
  69.  
  70.  
  71. variable dlgwin
  72.  
  73. // timer function to update the real-time clock
  74. function clocktick
  75.   oldwindow = gotowindow dlgwin
  76.   // YYYYMMDDWhhmmssuu
  77.   rawtime = getrawtime
  78.   writestr rawtime [10:2] + ' ' + rawtime [12:2] + ' ' +
  79.            rawtime [14:2] '' 8 8
  80.   writestr rawtime [3:2]  + ' ' + rawtime [5:2]  + ' ' +
  81.            rawtime [7:2] + ' ' + rawtime [9] '' 19 8
  82.   gotowindow oldwindow
  83. end
  84.  
  85. // create an alarm line on the dialog box
  86. private function alarmline (y line)
  87.   field ">"  8  y   9 line [1:8]
  88.   field ">" 19  y  11 line [9:10]
  89.   // trim trailing blanks for macro name
  90.   macro = line [19:11]
  91.   field ">" 32  y  11 macro [1 : posnot ' ' macro 'r']
  92.   field ">" 45  y  25 line [30:TO_END]
  93. end
  94.  
  95.  
  96. // alarm dialog box
  97. private function alarmdlg
  98.  
  99.   // load alarm field data
  100.   databuffer = loadbuf (bootpath "macro\\alarm.dat")
  101.   if databuffer then
  102.     initialset = if? (getlines > 4) (gettext '' '' 5) ''
  103.   end
  104.  
  105.   // create dialog box
  106.   dlgwin = dialog "Set Alarm" 71 11 "cp"
  107.  
  108.   writestr " ─ Time ─   ─ Date ─" '' 7 2
  109.   writestr " hh mm ss   yy mm dd w   Command      Parameter/Comment" '' 7 3
  110.  
  111.   groupbox 'Set' 3 3
  112.     (menu ''
  113.        item "[ ]"
  114.        item "[ ]"
  115.        item "[ ]"
  116.        item "[ ]"
  117.      end) '' initialset "1234"
  118.  
  119.   alarmline 4 (gettext '' '' 1 databuffer)
  120.   alarmline 5 (gettext '' '' 2 databuffer)
  121.   alarmline 6 (gettext '' '' 3 databuffer)
  122.   alarmline 7 (gettext '' '' 4 databuffer)
  123.  
  124.   destroybuf databuffer
  125.  
  126.   button "O&k"      27 10 8
  127.   button "Cancel"   38 10 8
  128.  
  129.   variable setopt
  130.   variable time1, date1, mac1, msg1
  131.   variable time2, date2, mac2, msg2
  132.   variable time3, date3, mac3, msg3
  133.   variable time4, date4, mac4, msg4
  134.  
  135.   // start real-time clock
  136.   clockid = setrepeat '' clock_delay (getcurrobj) "clocktick"
  137.   clocktick
  138.  
  139.   // get alarm times
  140.   value = getdialog ref setopt
  141.                     ref time1 ref date1 ref mac1 ref msg1
  142.                     ref time2 ref date2 ref mac2 ref msg2
  143.                     ref time3 ref date3 ref mac3 ref msg3
  144.                     ref time4 ref date4 ref mac4 ref msg4
  145.  
  146.   // destroy real-time clock
  147.   destroytimer clockid
  148.  
  149.   if value == 'Ok' then
  150.  
  151.     // turn alarms on/off
  152.     setalarm2 setopt 1 time1 date1 mac1 msg1
  153.     setalarm2 setopt 2 time2 date2 mac2 msg2
  154.     setalarm2 setopt 3 time3 date3 mac3 msg3
  155.     setalarm2 setopt 4 time4 date4 mac4 msg4
  156.  
  157.     // save all alarms to Alarm.dat
  158.     if createbuf '' time1:-8 + date1:-10 + mac1:-11 + msg1
  159.                     time2:-8 + date2:-10 + mac2:-11 + msg2
  160.                     time3:-8 + date3:-10 + mac3:-11 + msg3
  161.                     time4:-8 + date4:-10 + mac4:-11 + msg4
  162.                     setopt then
  163.       savebuf (bootpath "macro\\alarm.dat")
  164.       destroybuf
  165.     end
  166.   end
  167. end
  168.  
  169. // macro help
  170. macrofile = arg 1
  171. key <f1>
  172.   helpmacro macrofile
  173. end
  174.  
  175. // called by Lib.x when a key is entered in the dialog box
  176. function ondialog (keycode)
  177.   call keycode
  178. end
  179.  
  180. // display alarm dialog box
  181. alarmdlg
  182.